<?php

define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');

require(dirname(__FILE__) . '/includes/lib_comment.php');

if ((DEBUG_MODE & 2) != 2) $smarty->caching = true; 

/*------------------------------------------------------ */
//-- INPUT
/*------------------------------------------------------ */

$_REQUEST['id'] = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
$store_id     = $_REQUEST['id'];

/*------------------------------------------------------ */
//-- PROCESSOR
/*------------------------------------------------------ */

$cache_id = sprintf('%X', crc32($_REQUEST['id'] . '-' . $_CFG['lang']));

if (!$smarty->is_cached('store.dwt', $cache_id))
{
    $store = get_store_info($store_id);

    if (empty($store))
    {
        ecs_header("Location: ./\n");
        exit;
    }

    $smarty->assign('categories',       get_categories_tree());  // 分类树
    $smarty->assign('helps',            get_shop_help()); // 网店帮助
    $smarty->assign('top_goods',        get_top10());    // 销售排行
    $smarty->assign('best_goods',       get_recommend_goods('best'));       // 推荐商品
    $smarty->assign('new_goods',        get_recommend_goods('new'));        // 最新商品
    $smarty->assign('hot_goods',        get_recommend_goods('hot'));        // 热点文章
    $smarty->assign('promotion_goods',  get_promote_goods());    // 特价商品
    $smarty->assign('id',               $store_id);
    $smarty->assign('username',         $_SESSION['user_name']);
    $smarty->assign('email',            $_SESSION['email']);
    $smarty->assign('type',            '1');
    $smarty->assign('promotion_info', get_promotion_info());

    /* 验证码相关设置 */
    if ((intval($_CFG['captcha']) & CAPTCHA_COMMENT) && gd_version() > 0)
    {
        $smarty->assign('enabled_captcha', 1);
        $smarty->assign('rand',            mt_rand());
    }

    $smarty->assign('store',      $store);
    $smarty->assign('keywords',     htmlspecialchars($store['keywords']));
    $smarty->assign('description', htmlspecialchars($store['description']));

	assign_template();

    $position = assign_ur_here(0, $store['name']);
    $smarty->assign('page_title',   $position['title']);    // 页面标题
    $smarty->assign('ur_here',      $position['ur_here']);  // 当前位置
    $smarty->assign('comment_type', 1);

    assign_dynamic('store');
}
$smarty->display('store.dwt', $cache_id);


/*------------------------------------------------------ */
//-- PRIVATE FUNCTION
/*------------------------------------------------------ */

function get_store_info($store_id)
{
    $sql = "SELECT * FROM " .$GLOBALS['ecs']->table('store'). "WHERE id = '$store_id'";
    $row = $GLOBALS['db']->getRow($sql);

    return $row;
}

?>